package com.nsl.my_youlai.controller;

import com.nsl.my_youlai.common.result.Result;
import com.nsl.my_youlai.model.entity.MajorCategoryEntity;
import com.nsl.my_youlai.model.vo.options.MajorCategoryElSelectOption;
import com.nsl.my_youlai.service.MajorCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/v1/major_category")
@RequiredArgsConstructor
public class MajorCategoryController {

    private final MajorCategoryService majorCategoryService;

    @GetMapping("/level/{level}/all")
    public Result<List<MajorCategoryElSelectOption>> listMajorOptionsByLevel(@PathVariable Integer level){
        List<MajorCategoryElSelectOption> optionList=majorCategoryService.listByLevel(level);
        return Result.success(optionList);
    }

    @GetMapping("/level1/{firstLevelId}/level2/all")
    public Result<List<MajorCategoryElSelectOption>> getMajorCategoryOptionListOfSecondLevel(@PathVariable Integer firstLevelId){
        List<MajorCategoryElSelectOption> optionList=majorCategoryService.getMajorCategoryOptionListOfSecondLevel(firstLevelId);
        return Result.success(optionList);
    }

    //todo: 使用vo传递数据，不必要的字段不必传输
    @GetMapping("/list")
    public Result<List<MajorCategoryEntity>> listAllMajorOptions(){
        List<MajorCategoryEntity> optionList=majorCategoryService.list();
        return Result.success(optionList);
    }

}
